package Study;
import java.util.*;
public class Test {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        boolean flag=true;
        Map<Integer,Integer> map=new HashMap<Integer,Integer>();
        while(flag){
            System.out.println("****************");
            System.out.println("1.添加学生分数信息");
            System.out.println("2.删除学生分数信息");
            System.out.println("3.所有学生信息");
            System.out.println("4.退出系统");
            System.out.println("****************");
            System.out.println("请选择:");
            int choice=sc.nextInt();
            switch(choice){
                case 1:
                    addStudent(map);
                    break;
                case 2:
                    delStudent(map);
                    break;
                case 3:
                    selAllStudent(map);
                    break;
                case 4:
                    flag=false;
                    System.out.println("系统退出!");
            }
        }
    }
    public static void addStudent(Map<Integer,Integer> map){
        boolean tag=true;
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入学生ID:");
        int studentID=sc.nextInt();
        for(int key:map.keySet()){
            if(key==studentID){
                System.out.println("该学生ID已经存在，添加失败!");
                tag=false;
                break;
            }
        }
        if(tag){
            System.out.println("请输入学生的分数信息:");
            int score=sc.nextInt();
            map.put(studentID,score);
            System.out.println("学生信息添加成功!");
        }
    }
    public static void delStudent(Map<Integer,Integer> map){
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入删除学生ID:");
        int studentID=sc.nextInt();
        map.remove(studentID);
        System.out.println("学生分数删除成功!");
    }
    public static void selAllStudent(Map<Integer,Integer> map) {
       for(Map.Entry<Integer,Integer> entry:map.entrySet()){
           System.out.println("ID      分数");
           System.out.println(entry.getKey()+"      "+entry.getValue());
       }
    }
}
